<?php

/* @var $this \yii\web\View */
/* @var $content string */

use yii\helpers\Html;
use app\assets\AppAsset;
use \yii\helpers\Url;

AppAsset::register($this);
$this->title = '登录';
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="container">

    <div class="row" style="padding-top: 28%;">
        <div>
        <form class="form-horizontal" id="userForm" method="post" action="<?=  Url::toRoute('login/submit') ?>" onsubmit="return false;">
            <div class="form-group">
                <label for="inputAccount" class="col-sm-2 control-label">账号</label>
                <div class="col-sm-4">
                    <input type="text" name="username" class="form-control" id="inputAccount" placeholder="账号">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword" class="col-sm-2 control-label">密码</label>
                <div class="col-sm-4">
                    <input type="password" name="password" class="form-control" id="inputPassword" placeholder="密码">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-4">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox"> 记住
                        </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-4">
                    <a href="javascript:void (0);" class="btn   btn-default  loginSub">登录</a>
                </div>
            </div>
        </form>
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        hello
    </div>
</div>
<?php $this->endBody() ?>
<script>
    $(document).ready(function(){
       $(".loginSub").on('click',function(){

           var loadIndex = 0;

           $.ajax({
               type: "POST",
               url:"<?=  Url::toRoute('login/submit') ?>",
               data: $('#userForm').serialize(),
               dataType: 'json',
               beforeSend:function(){
                   loadIndex = layer.load(1);
               },
               complete:function(){
                   layer.close(loadIndex);
               },
               success: function (msg) {
                   layer.msg(msg['msg']);
                   if (msg['code'] == 2) {
                       window.location.href = "<?=  Url::toRoute('home/index') ?>";
                   }
               }
           });
       });
    });
</script>
</body>
</html>
<?php $this->endPage() ?>
